let total = 0.00;
//获得用户id
const userId = localStorage.getItem("user_id");
console.log(userId);
if(userId != undefined && userId != null){
	const userName = localStorage.getItem("user_name");
	let userInfo = '';
	let info = document.querySelector(".h_content li");
	userInfo = "<a href='login.html' id='userInfo'>" +
	"<img id='userImg' src='img/user.jpg'>" +
	"<span>"+userName+"</span>"
	"<a>";
	info.innerHTML = userInfo;
}

// 商品分类
(function() {
	ajax({
		method: 'GET',
		url: BASE_URL + '/api_cat',
		type: 'JSON',
		callback: function(data) {
			let typelist = document.querySelector(".type_list>ul")
			let goodListData = data.data;
			let text = ''
			goodListData.forEach((item) => {
				text += "<li><a href='goodlist.html?search_type=2&cat_id="+item.cat_id+"&cat_name="+item.cat_name+"'><img src='" + item.cat_img + "'><p>" + item.cat_name +
					"</p></a></li>"
			})
			typelist.innerHTML = text
		}
	})
})();
// 关闭二维码窗口
let close = document.querySelector("button[class='close']")
close.addEventListener('click', () => {
	let qrCode = document.querySelector("div[class='qrCode']")
	qrCode.style.display = 'none'
})
let arrow = document.querySelector("div[class='arrow']")
// 下滑显示和隐藏箭头
window.addEventListener('scroll', () => {
	let scollY = window.scrollY
	let arrow = document.querySelector("div[class='arrow']")
	if (scollY >= 200) {
		arrow.style.display = 'block'
	} else {
		arrow.style.display = 'none'
	}
})
// 点击箭头回到顶部
arrow.addEventListener('click', () => {
	window.scrollTo({
		top: 0, //距离顶部的距离
		behavior: 'smooth' //滑动的方式
	})
})

// 关键字搜索查询
let search = document.querySelector(".search_btn");
search.addEventListener('click',()=>{
	let keyword = document.querySelector("input[name='keyWords']").value;
	window.location.href = "goodlist.html?search_type=1&keywords="+keyword;
})


